
package gui.std;

import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JPanel;

import app.User;

@SuppressWarnings("serial")
public class GUserList extends JPanel {
	
	public GUserList() {
		setLayout(new GridLayout(0, 1, 2, 2));
	}
	
	public void setUser(User u) {
		user = u;
	}
	
	public void setDisplay(JPanel d) {
		display = d;
	}
	
	public JPanel getDisplay() {
		return display;
	}
	
	public void addActionListener(ActionListener e) {
		action = e;
	}
	
	public void update(Vector<User> v) {
		removeAll();
		for (User i : v) {
			GUserItem it = new GUserItem(i);
			it.setDisplay(display);
			
			if ((user != null) && (user.compareTo(i) == 0)) {
				it.mark();
			}
			else {
				if (action != null) {
					it.addActionListener(action);
				}
			}
			add(it);
		}
		updateUI();
	}
	
	private JPanel display;
	private User user;
	private ActionListener action;
}
